﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Security.Cryptography;

namespace YBApproval.Common
{
    public class SequenceNumberCreator
    {
        ///// <summary>
        ///// 
        ///// </summary>
        //private static Int64 seed = Int64.Parse(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString("0"));

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <returns></returns>
        //public static Int64 GetPrimaryKey()
        //{
        //    return Interlocked.Increment(ref seed);
        //}

        /// <summary>
        /// 时间戳加GUID法
        /// </summary>
        /// <returns></returns>
        public static string GetSquenceNumberInString1(){
            string a = String.Format("{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), Guid.NewGuid().ToString().Split('-')[4]);
            return a;
        }

        /// <summary>
        /// 乱数生成发
        /// </summary>
        /// <returns></returns>
        public static string GetSquenceNumberInString()
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            byte[] random = new Byte[3];
            rng.GetBytes(random);

            StringBuilder str = new StringBuilder(random.Length * 2);

            foreach (byte b in random)
            {
                str.AppendFormat("{0:X2}", b);
            }

            return String.Format("{0}{1}", DateTime.Now.ToString("yyyyMMddHHmm"), str.ToString());
        }
    }
}
